var client = require("../DAOImpl/mongodb");
var dataConfig = require("../config/database.json");
var host = dataConfig.host;
var database = dataConfig.db;
var db = new client(host, database);
var status = require("../config/status.json");

var currentLat = 31.2051659;
var currentLng = 121.5854;
/*
 * @req.body: dri_id cus_id
 * @res send the driver position info for example: {
 * 'statusCode' : '0', 'driverId' : '1', 'currentLat' : currentLat, 'currentLng' :
 * currentLng, 'distance' : '200', 'saveTime' : '2' };
 */
function getDriverPosition(req, res, next) {
	console.log('getDriverPosition');
	
	var result = new Object();

	result.status = status.SUCCESS.VALUE;
	
	result.dri_info = new Object();
	result.dri_info.id = 123;
	currentLat = currentLat + 0.001;
	result.dri_info.lat = currentLat;
	currentLng = currentLng + 0.001;
	result.dri_info.lng = currentLng;
	result.distance = 123;
	result.saveTime = 1;
	
	res.send(result);
	return next();
}

/*
 * @req.body:dri_id, cus_id The customer accept the request which is sent from
 * the driver who wants to accept the order.
 */
function acceptDriver(req, res, next) {
	console.log("acceptDriver");
	var result = new Object();

	result.status = status.SUCCESS.VALUE;
	
	result.dri_info = new Object();
	result.dri_info.id = 123;
	result.dri_info.lat = currentLat - 0.001;
	result.dri_info.lng = currentLng - 0.001;
	result.distance = 123;
	result.saveTime = 1;
	res.send(result);

	
	return next();
}

/*
 * @req.body: cus_id
 */
function cancelRequestDriver(req, res, next) {
	var result = new Object();
	var selector = new Object();
	var documnet = new Object();
	selector.cus_id = req.body.cus_id;

	documnet.status = 1;// 
	
			result.status = status.ERROR.VALUE;
			res.send(result);
	
	return next;
}

/*
 * @req.body:cus_id, dri_id {'cus_id': '1','dri_id':'2'}
 */
function refuseDriver(req, res, next) {
	var result = new Object();
	var selector = new Object();
	var document = new Obejct();


			result.status = status.SYSTEMERROR.VALUE;
			res.send(result);


	return next;
}

/*
 * @req.body:order_id, result {'order_id': '1', 'result':'5'}
 */
function assessDriver(req, res, next) {
	var result = new Object();
	var selector = new Object();
	var document = new Obejct();

	selector.order_id = req.body.order_id;
	selector.result = req.body.result;
	document.status = status.EVALUATION[req.body.result].VALUE;

	
			result.status = status.SYSTEMERROR.VALUE;
			res.send(result);

	return next;
}
exports.services = [ getDriverPosition, cancelRequestDriver, refuseDriver,
		acceptDriver, assessDriver ];